const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    lists:[],
    isagree:false,
    id:'',
    banner:''
  },
  onLoad(options){
    this.appinfo()
    if(options.parentid){
      app.globalData.parentid=options.parentid
    }
  },
  onShow: function (options) {
    this.lists()
  },
  lists(source){
    Controller.vipPackageList().then(res=>{
      if(res.data.baseData && res.data.baseData.length>0){
        var lists=res.data.baseData;
        var id=''
        for(var i=0;i<lists.length;i++){
          if(i==0){
            lists[i].select=true
            var id=lists[i].id
          }else{
            lists[i].select=false
          }
          
        }
        this.setData({
          lists,
          id
        })
      }
    })
  },
  appinfo(){
    Controller.appinfo({key:'key-vip-info-img'}).then(res=>{
      if(res.data.baseData){
        if(res.data.baseData.content){
          var content=res.data.baseData.content
          this.setData({
            banner:res.data.baseData.content
          })
        }
      }
    })
  },
  goagree(){
    wx.navigateTo({
      url: "/pages/doc/doc?key=key-vip-agreement&name=会员升级服务协议"
    })
  },
  select(e) {
    var index=e.currentTarget.dataset.index;
    var lists=this.data.lists;
    var id=e.currentTarget.dataset.id
    for(let item of lists){
      item.select=false
    }
    lists[index].select=true
    
    this.setData({
      lists,
      id
    })
  },
  agree(e){
    this.setData({
      isagree:!this.data.isagree
    })
  },
  pay(e){
    if (!this.data.isagree) {
        wx.showToast({
          title: "请阅读",
          icon: 'none',
          duration: 1000
        });
        return
    }
    if (!this.data.id) {
        wx.showToast({
          title: "请选择套餐",
          icon: 'none',
          duration: 1000
        });
        return
    }
    wx.navigateTo({
      url: '/pages/mall/order?id='+this.data.id+"&type=vip&ordertype=6&source=VIP"
    })

  },
  onShareAppMessage: function (e) {
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
  onShareTimeline: function(res){
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
})